package com.dfrz.ch07.stuTast;

import java.util.Random;
import java.util.Scanner;

/**
 * 作者：wangmaokang
 * 日期: 2021/4/15 9:31
 * 描述:
 */
public class GuessNum {
    public static void main(String[] args) {
        Random r1 = new Random();
        int i = r1.nextInt(100);//0-100之间的随机数
        Scanner sca = new Scanner(System.in);
        int count = 0;//累计输入的次数

        while (true) {
            System.out.println("请输入0-100之间的数字");
            int y = sca.nextInt();
            if (y > i) {
                System.out.println("猜大了");
                count++;//count=count+1;
            } else if (y < i) {
                System.out.println("猜小了");
                count++;
            } else {
                System.out.println("猜对了");
                System.out.println(++count + "次");
            }
        }

    }
}